package pri.zxx.learndemo.javabase.listdemo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ListTest {
    /**
     * desc: 二分查找
     **/
    public static void binarySearchTest() {
        int[] arr = new int[]{1, 5, 44, 3, 2, 5, 5, 9};
        Arrays.sort(arr);
        for (int i : arr) {
            System.out.print(i + ",");
        }
        System.out.println();
        System.out.println("search 4 : ");
        int index = Arrays.binarySearch(arr, 4);
        System.out.println("index : " + index);
        //System.out.println(" ; arr[4] = "+arr[index+1]);
    }

    public static void main(String[] args) {
        binarySearchTest();
        String s = "aaaabbbccc";
        Map<String, Long> collect = toCharacter(s).map(String::valueOf)
                .collect(Collectors.groupingBy(s1 -> s1, Collectors.counting()));
        String collect1 = collect.keySet().stream().map(s1 -> s1 + collect.get(s1))
                .collect(Collectors.joining());
        System.out.println(collect1);
    }
    static Stream<Character> toCharacter(String str) {
        final char[] chars = str.toCharArray();
        final ArrayList<Character> list = new ArrayList<>();
        for (char aChar : chars) {
            list.add(aChar);
        }
        return list.stream();
    }
}
